require('dotenv').config();
const mongoose = require('mongoose');

const testConnection = async () => {
  try {
    // 连接数据库
    await mongoose.connect(process.env.MONGODB_URI);
    console.log('✅ MongoDB 连接成功！');
    
    // 测试数据库操作
    const collections = await mongoose.connection.db.listCollections().toArray();
    console.log('📚 数据库中的集合:', collections.map(c => c.name));

    // 测试完成后断开连接
    await mongoose.connection.close();
    console.log('✅ 数据库连接已关闭');
  } catch (error) {
    console.error('❌ 连接错误:', error.message);
  }
};

testConnection();